<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="div">
        <input type="checkbox" name="a" value="语文">语文
        <input type="checkbox" name="a" value="数学">数学
        <input type="checkbox" name="a" value="英语">英语
        <input type="checkbox" name="a" value="物理">物理
        <input type="checkbox" name="a" value="历史">历史
    </div>
    <p></p>
    <script>
        var div =document.getElementById('div');
        var input=document.querySelectorAll('input');
        var length=input.length;
        var p=document.querySelector('p');
        div.onchange=function (){
             var text='';
            for (let i = 0; i < length; i++) {
            if (input[i].checked==true) {
                text+=input[i].value+' ';
            }
        }
        if(text==''){
            p.innerText='';
        }else{
           p.innerText=`您选择了${text}`; 
        }
        
        }
    </script>
</body>
</html>